<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增文档管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dm-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">栏目分类：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="cid" type="hidden"/>
                        <input class="form-control" type="text" onclick="selectCategoryTree()" id="treeName" name="cname" readonly="true">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">标题：</label>
                <div class="col-sm-8">
                    <input name="title" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">摘要：</label>
                <div class="col-sm-8">
                    <textarea name="abstractstr" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">语言：</label>
                <div class="col-sm-8">
                    <select name="language" class="form-control m-b" th:with="type=${@dict.getType('language_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">链接：</label>
                <div class="col-sm-8">
                    <input id="link" name="link" class="form-control" type="text">
                </div>
            </div>
            <input id="hfile" name="file" class="form-control" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">文件：</label>
                <div class="col-sm-8">
                    <label class="font-noraml"></label>
                    <div class="file-loading">
                        <input id="fileinput" type="file" multiple>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "cms/dm"
        $("#form-dm-add").validate({
            focusCleanup: true
        });

        function submitHandler() {

            if($("#link").val() == '' && $("#hfile").val() == ''){
                alert("链接和文件至少需要一个");
                return;
            }

            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-dm-add').serialize());
            }
        }

        $(document).ready(function () {
            $("#fileinput").fileinput({
                uploadUrl: "/businessfile/file/addfile",
                uploadAsync:true,
                maxFileCount:1,
                dropZoneTitle:"拖拽文件到这里...<br/>最大文件体积25MB"
            });

            $("#fileinput").on("fileuploaded", function (event, data, previewId, index) {
                $("#hfile").val(data.response.data);
            })

        });

        /*栏目分类选择*/
        function selectCategoryTree() {
            var prefixTemp = ctx + "cms/category"
            var options = {
                title: '栏目分类选择',
                width: "380",
                url: prefixTemp + "/selectCategoryTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    </script>
</body>
</html>
